package com.niit.scs.liteframework.coursepractiseserver.controller;

import com.niit.scs.liteframework.coursepractiseserver.service.dto.BaseClassInfo;
import com.niit.scs.liteframework.coursepractiseserver.service.dto.StudentDTO;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
public class Unit1Controller {
    @GetMapping("/helloworld2")
    public ResponseEntity Helloworld(){
        String result="Hello world.";
        return ResponseEntity.ok(result);
    }
    @GetMapping("/helloworld/student")
    public ResponseEntity getStudentInfo(){
        //定义返回的学生对象
        StudentDTO result=new StudentDTO();
        //定义学生所在班级对象，赋值班级各字段信息
        BaseClassInfo classInfo=new BaseClassInfo();
        classInfo.setClassCode("20190278001");
        classInfo.setClassName("移动1913");
        classInfo.setClassYear(2019);
        //赋值返回的学生各字段信息
        result.setStudentCode("0003319");
        result.setStudentName("测试学生");
        //将以上定义的班级赋值到班级字段中
        result.setClassInfo(classInfo);
        //定义舍友数组
        List<StudentDTO> roommates=new ArrayList<StudentDTO>();
        //模拟第1个舍友信息
        StudentDTO roomate1=new StudentDTO();
        roomate1.setStudentCode("student1");
        roomate1.setStudentName("舍友1");
        roomate1.setClassInfo(classInfo);
        roommates.add(roomate1);
        //模拟第2个舍友信息
        StudentDTO roomate2=new StudentDTO();
        roomate2.setStudentCode("student2");
        roomate2.setStudentName("舍友2");
        roomate2.setClassInfo(classInfo);
        roommates.add(roomate2);
        //模拟第3个舍友信息
        StudentDTO roomate3=new StudentDTO();
        roomate3.setStudentCode("student3");
        roomate3.setStudentName("舍友3");
        roomate3.setClassInfo(classInfo);
        roommates.add(roomate3);
        //将构造完成的舍友List赋值给舍友字段
        result.setRoommates(roommates);
        //返回学生对象
        return ResponseEntity.ok(result);
    }
}
